package com.legendshop.openportal.sdk.client.http.analyzer;

import cn.hutool.http.HttpResponse;
import com.legendshop.openportal.sdk.client.http.HttpResponseAnalyzer;
import com.legendshop.openportal.sdk.client.http.HttpResponseAnalyzerContext;
import com.legendshop.openportal.sdk.model.OpenResult;
import com.legendshop.openportal.sdk.utils.ConvertUtil;

import java.lang.reflect.Type;

/**
 * @author jzh
 * @version 1.0.0
 * @title JsonResponseAnalyzer
 * @date 2024/6/18 17:51
 * @description：json结果解析器，返回的结果里不包含OpenResult
 */
public class JsonResponseAnalyzer implements HttpResponseAnalyzer {

    private static final JsonResponseAnalyzer INSTANCE = new JsonResponseAnalyzer();

    private JsonResponseAnalyzer() {}

    public static JsonResponseAnalyzer getInstance() {
        return INSTANCE;
    }

    @Override
    public <T> OpenResult<T> analyze(HttpResponse httpResponse, Type responseClass) {
        return ConvertUtil.convert2OpenResult(HttpResponseAnalyzerContext.get(), responseClass);
    }
}
